import request from '@/utils/request';

/**
 * 分页查询荣誉资质
 * @param params 查询条件
 */
export async function pageHonors(params) {
  const res = await request.get('/business/honor/page', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询荣誉资质列表
 * @param params 查询条件
 */
export async function listHonors(params) {
  const res = await request.get('/business/honor', {
    params
  });
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 根据id查询荣誉资质
 * @param id 荣誉资质id
 */
export async function getHonor(id) {
  const res = await request.get('/business/honor/' + id);
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加荣誉资质
 * @param data 荣誉资质信息
 */
export async function addHonor(data) {
  const res = await request.post('/business/honor', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改荣誉资质
 * @param data 荣誉资质信息
 */
export async function updateHonor(data) {
  const res = await request.put('/business/honor', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除荣誉资质
 * @param id 荣誉资质id
 */
export async function removeHonor(id) {
  const res = await request.delete('/business/honor/' + id);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 批量删除荣誉资质
 * @param data 荣誉资质id集合
 */
export async function removeHonors(data) {
  const res = await request.delete('/business/honor/batch', {
    data
  });
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改产品状态
 * @param ProductId 产品id
 * @param status 状态
 */
export async function updateHonorStatus(id, statusFlag) {
  const res = await request.get('/business/product/status', {
    params: {
      id,
    }
  });
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

